//
//  BIZFeaturePlayerTableViewCell.m
//  biz
//
//  Created by zhangfuwei on 2017/3/20.
//  Copyright © 2017年 jieshuibao. All rights reserved.
//

#import "BIZFeaturePlayerTableViewCell.h"
#import "BIZMoviePlaySitcomListDataModel.h"

@interface BIZFeaturePlayerTableViewCell ()

//@property (strong, nonatomic) IBOutlet UIImageView *movieBgImgV;
//@property (strong, nonatomic) IBOutlet UIButton *movieStartButton;
//@property (strong, nonatomic) IBOutlet UILabel *watchedLabel;
//@property (strong, nonatomic) IBOutlet UIView *topGraySepratedView;
//@property (strong, nonatomic) IBOutlet NSLayoutConstraint *topGraySepratedViewH;
@property (strong, nonatomic)  UIImageView *movieBgImgV;
@property (strong, nonatomic)  UIImageView *movieBeginImgV;
/** 播放次数 */
@property (strong, nonatomic)  UILabel *watchedLabel;
/** 顶部分割视图 */
@property (strong, nonatomic)  UIView *grayView;
/** 花边 */
@property (nonatomic, strong) UIImageView *laceImgV;


@property (strong, nonatomic)  NSLayoutConstraint *topGraySepratedViewH;

@end

@implementation BIZFeaturePlayerTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
//        [self loadUI];
    }
    return self;
}

//- (void)loadUI {
//    _movieBgImgV = [[UIImageView alloc] init];
//    _movieBeginImgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"movie_start"]];
//    _grayView = [[UIView alloc] init];
//    _grayView.backgroundColor = HEXCOLOR(0xe6e6e6);
//    
//    _laceImgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"movie_lace"]];
//    
//    _watchedLabel = [UILabel new];
//    _watchedLabel.textAlignment = NSTextAlignmentRight;
//    
//    [self.contentView addSubview:_movieBgImgV];
//    [self.contentView addSubview:_movieBeginImgV];
//    [self.contentView addSubview:_grayView];
//    [self.contentView addSubview:_laceImgV];
//    [self.contentView addSubview:_watchedLabel];
//    
//}


- (void)layoutSubviews {
    [super layoutSubviews];
    [self.grayView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(self.contentView);
        make.height.equalTo(@10);
    }];
    
    [self.movieBgImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.grayView.mas_bottom).offset(14);
        make.left.equalTo(self.contentView).offset(15);
        make.right.equalTo(self.contentView).offset(-15);
        make.height.equalTo(@135);
    }];
    
    [self.movieBeginImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.movieBgImgV);
        make.height.width.equalTo(@32);
    }];
    
    [self.laceImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.movieBgImgV.mas_bottom).offset(13);
        make.left.equalTo(self.movieBgImgV);
        make.height.equalTo(@22);
        make.width.equalTo(@258);
        make.bottom.equalTo(self.contentView);
    }];
    
    [self.watchedLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.movieBgImgV);
        make.centerY.equalTo(self.laceImgV);
        make.height.equalTo(@10);
    }];
    
}

- (void)setSitcomListDataM:(BIZMoviePlaySitcomListDataModel *)sitcomListDataM {
    
    _sitcomListDataM = sitcomListDataM;
    self.grayView.backgroundColor = COLOR_UNLINE_GREY;
    
    [SDWebImageTool imageView:self.movieBgImgV
                    imageName:sitcomListDataM.cover
                  placeHolder:@"movie_cover"
                 showProgress:NO];
    
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%ld人观看",sitcomListDataM.watchNum] attributes:@{NSFontAttributeName:CHINESE_SYSTEM(10),NSForegroundColorAttributeName:HEXCOLOR(0x999999)}];
    [attStr addAttributes:@{NSFontAttributeName:CHINESE_SYSTEM(10),NSForegroundColorAttributeName:HEXCOLOR(0x2dace7)} range:NSMakeRange(0, [[NSString stringWithFormat:@"%ld",sitcomListDataM.watchNum] length])];
    
    
    self.watchedLabel.attributedText = attStr;
    [self layoutIfNeeded];
}

- (void)setRow:(NSInteger)row {
    _row = row;
    CGFloat H = !row ? 10:0;
    [self.grayView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(self.contentView);
        make.height.equalTo(@(H));
    }];
}

#pragma mark -- 懒加载

- (UIImageView *)movieBgImgV {
    if (!_movieBgImgV) {
        _movieBgImgV = [[UIImageView alloc] init];
        [self.contentView addSubview:_movieBgImgV];
    }
    return _movieBgImgV;
}

- (UIImageView *)movieBeginImgV {
    if (!_movieBeginImgV) {
        _movieBeginImgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"movie_start"]];
        [self.contentView addSubview:_movieBeginImgV];
        
    }
    return _movieBeginImgV;
}

- (UIView *)grayView {
    if (!_grayView) {
        _grayView = [[UIView alloc] init];
        _grayView.backgroundColor = HEXCOLOR(0xe6e6e6);
        [self.contentView addSubview:_grayView];
        
    }
    return _grayView;
}

- (UILabel *)watchedLabel {
    if (!_watchedLabel) {
        _watchedLabel = [UILabel new];
        _watchedLabel.textAlignment = NSTextAlignmentRight;
        [self.contentView addSubview:_watchedLabel];
        
    }
    return _watchedLabel;
}

- (UIImageView *)laceImgV {
    if (!_laceImgV) {
        _laceImgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"movie_lace"]];
        [self.contentView addSubview:_laceImgV];
        
    }
    return _laceImgV;
}

@end
